﻿using System;
using UnityEngine;
using UnityEngine.UI;

// Token: 0x0200015B RID: 347
[AddComponentMenu("RVP/C#/Demo Scripts/Vehicle Menu", 0)]
[DisallowMultipleComponent]
public class VehicleMenu : MonoBehaviour
{
	// Token: 0x06000645 RID: 1605 RVA: 0x00034B40 File Offset: 0x00032D40
	private void Update()
	{
		this.autoShift = this.autoShiftToggle.isOn;
		this.assist = this.assistToggle.isOn;
		this.stuntMode = this.stuntToggle.isOn;
		this.cam.stayFlat = this.camToggle.isOn;
		this.chaseCarSpawnTime = Mathf.Max(0f, this.chaseCarSpawnTime - Time.deltaTime);
		if (this.vp)
		{
			this.speedText.text = (this.vp.velMag * 2.23694f).ToString("0") + " MPH";
			if (this.trans)
			{
				if (this.gearbox)
				{
					this.gearText.text = "Gear: " + ((this.gearbox.currentGear != 0) ? ((this.gearbox.currentGear != 1) ? (this.gearbox.currentGear - 1).ToString() : "N") : "R");
				}
				else if (this.varTrans)
				{
					this.gearText.text = "Ratio: " + this.varTrans.currentRatio.ToString("0.00");
				}
			}
			if (this.engine)
			{
				this.rpmMeter.value = this.engine.targetPitch;
				if (this.engine.maxBoost > 0f)
				{
					this.boostMeter.value = this.engine.boost / this.engine.maxBoost;
				}
			}
			if (this.stuntMode && this.stunter)
			{
				this.stuntEndTime = ((!string.IsNullOrEmpty(this.stunter.stuntString)) ? 2f : Mathf.Max(0f, this.stuntEndTime - Time.deltaTime));
				if (this.stuntEndTime == 0f)
				{
					this.stuntText.text = string.Empty;
				}
				else if (!string.IsNullOrEmpty(this.stunter.stuntString))
				{
					this.stuntText.text = this.stunter.stuntString;
				}
				this.scoreText.text = "Score: " + this.stunter.score.ToString("n0");
			}
			if (this.propertySetter)
			{
				this.propertySetterText.text = ((this.propertySetter.currentPreset != 0) ? ((this.propertySetter.currentPreset != 1) ? "Crab Steering" : "Skid Steering") : "Normal Steering");
			}
		}
	}

	// Token: 0x06000646 RID: 1606 RVA: 0x00034E3C File Offset: 0x0003303C
	public void SpawnVehicle(int vehicle)
	{
		this.newVehicle = UnityEngine.Object.Instantiate<GameObject>(this.vehicles[vehicle], this.spawnPoint, Quaternion.LookRotation(this.spawnRot, GlobalControl.worldUpDir));
		this.cam.target = this.newVehicle.transform;
		this.cam.Initialize();
		this.vp = this.newVehicle.GetComponent<VehicleParent>();
		this.trans = this.newVehicle.GetComponentInChildren<Transmission>();
		if (this.trans)
		{
			this.trans.automatic = this.autoShift;
			this.newVehicle.GetComponent<VehicleParent>().brakeIsReverse = this.autoShift;
			if (this.trans is GearboxTransmission)
			{
				this.gearbox = (this.trans as GearboxTransmission);
			}
			else if (this.trans is ContinuousTransmission)
			{
				this.varTrans = (this.trans as ContinuousTransmission);
				if (!this.autoShift)
				{
					this.vp.brakeIsReverse = true;
				}
			}
		}
		if (this.newVehicle.GetComponent<VehicleAssist>())
		{
			this.newVehicle.GetComponent<VehicleAssist>().enabled = this.assist;
		}
		if (this.newVehicle.GetComponent<FlipControl>() && this.newVehicle.GetComponent<StuntDetect>())
		{
			this.newVehicle.GetComponent<FlipControl>().flipPower = ((!this.stuntMode || !this.assist) ? Vector3.zero : new Vector3(10f, 10f, -10f));
			this.newVehicle.GetComponent<FlipControl>().rotationCorrection = ((!this.stuntMode) ? ((!this.assist) ? Vector3.zero : new Vector3(5f, 1f, 10f)) : Vector3.zero);
			this.newVehicle.GetComponent<FlipControl>().stopFlip = this.assist;
			this.stunter = this.newVehicle.GetComponent<StuntDetect>();
		}
		this.engine = this.newVehicle.GetComponentInChildren<Motor>();
		this.propertySetter = this.newVehicle.GetComponent<PropertyToggleSetter>();
		this.stuntText.gameObject.SetActive(this.stuntMode);
		this.scoreText.gameObject.SetActive(this.stuntMode);
	}

	// Token: 0x06000647 RID: 1607 RVA: 0x000350A8 File Offset: 0x000332A8
	public void SpawnChaseVehicle()
	{
		if (this.chaseCarSpawnTime == 0f)
		{
			this.chaseCarSpawnTime = 1f;
			GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.chaseVehicle, this.spawnPoint, Quaternion.LookRotation(this.spawnRot, GlobalControl.worldUpDir));
			gameObject.GetComponent<FollowAI>().target = this.newVehicle.transform;
		}
	}

	// Token: 0x06000648 RID: 1608 RVA: 0x00035108 File Offset: 0x00033308
	public void SpawnChaseVehicleDamage()
	{
		if (this.chaseCarSpawnTime == 0f)
		{
			this.chaseCarSpawnTime = 1f;
			GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.chaseVehicleDamage, this.spawnPoint, Quaternion.LookRotation(this.spawnRot, GlobalControl.worldUpDir));
			gameObject.GetComponent<FollowAI>().target = this.newVehicle.transform;
		}
	}

	// Token: 0x040009CE RID: 2510
	public CameraControl cam;

	// Token: 0x040009CF RID: 2511
	public Vector3 spawnPoint;

	// Token: 0x040009D0 RID: 2512
	public Vector3 spawnRot;

	// Token: 0x040009D1 RID: 2513
	public GameObject[] vehicles;

	// Token: 0x040009D2 RID: 2514
	public GameObject chaseVehicle;

	// Token: 0x040009D3 RID: 2515
	public GameObject chaseVehicleDamage;

	// Token: 0x040009D4 RID: 2516
	private float chaseCarSpawnTime;

	// Token: 0x040009D5 RID: 2517
	private GameObject newVehicle;

	// Token: 0x040009D6 RID: 2518
	private bool autoShift;

	// Token: 0x040009D7 RID: 2519
	private bool assist;

	// Token: 0x040009D8 RID: 2520
	private bool stuntMode;

	// Token: 0x040009D9 RID: 2521
	public Toggle autoShiftToggle;

	// Token: 0x040009DA RID: 2522
	public Toggle assistToggle;

	// Token: 0x040009DB RID: 2523
	public Toggle stuntToggle;

	// Token: 0x040009DC RID: 2524
	public Text speedText;

	// Token: 0x040009DD RID: 2525
	public Text gearText;

	// Token: 0x040009DE RID: 2526
	public Slider rpmMeter;

	// Token: 0x040009DF RID: 2527
	public Slider boostMeter;

	// Token: 0x040009E0 RID: 2528
	public Text propertySetterText;

	// Token: 0x040009E1 RID: 2529
	public Text stuntText;

	// Token: 0x040009E2 RID: 2530
	public Text scoreText;

	// Token: 0x040009E3 RID: 2531
	public Toggle camToggle;

	// Token: 0x040009E4 RID: 2532
	private VehicleParent vp;

	// Token: 0x040009E5 RID: 2533
	private Motor engine;

	// Token: 0x040009E6 RID: 2534
	private Transmission trans;

	// Token: 0x040009E7 RID: 2535
	private GearboxTransmission gearbox;

	// Token: 0x040009E8 RID: 2536
	private ContinuousTransmission varTrans;

	// Token: 0x040009E9 RID: 2537
	private StuntDetect stunter;

	// Token: 0x040009EA RID: 2538
	private float stuntEndTime = -1f;

	// Token: 0x040009EB RID: 2539
	private PropertyToggleSetter propertySetter;
}
